<template>
    <view class="warpper" :class="uiStyle == 1 ? '' : 'uiStyle'">
        <!-- index.wxml -->

        <van-toast id="van-toast" />
        <view class="top-box">
            <view class="contain-box" style="top: 30rpx" :style="weixin != 2 ? 'padding-left:30rpx;' : ''">
                <!-- <view class="logo">
      <image src="/assets/img/fixedLogo.png"></image>
    </view> -->
                <view class="search-div">
                   <view class="logo" v-if="weixin == 2" @tap="goBack2">
                        <van-icon name="arrow-left" size="22" />
                    </view>
                    <!-- 采用此写法是为了兼容大屏端 -->
                    <view class="search-div-cont">
                        <image src="../../static/assets/img/sous.png"></image>
                        <input @confirm="getParklist" @blur="getParklist" class="search-div-cont-text" v-model="searchName" placeholder="搜索目的地/车场名称" />
                        <view @tap.stop.prevent="clearInput" v-if="searchName" style="color: #000; position: relative; right: -10rpx">x</view>
                    </view>
                </view>
				<view class="maplist" @tap="goMap()">
					<image class="listImg" src="../../static/assets/img/mapList.png" mode=""></image>
					<view>切换地图模式</view>
				</view>
            </view>
        </view>
        <!-- <view class="map" wx:if="{{showPop}}">
  <map id="mymap" class="mapcontainer" style="height:{{showPop?screenHeightRPX-500 : mapHeight}}rpx" longitude="{{center[0]}}" latitude="{{center[1]}}" show-location="true" markers="{{markers}}" bindmarkertap="markerTap" scale="15" bindlabeltap="markerTap"></map>
  <view class="viewlistd" bindtap="moveTolocation" style="top:{{showPop?'750' :'520'}}rpx">
    <view class="viewlistblock" style="background:none;">
      <view class="viewlittle" style="padding:0;">
        <image src="../../assets/img/location.png" mode="" class="" id="" style="width:70rpx;height:70rpx;"></image>
      </view>
    </view>
  </view>
</view> -->

        <!-- 全部车位列表 -->
        <view class="btm allPark" v-if="allParkFlag && !showPop">
            <view class="line"></view>
            <view class="search-contain">
                <view class="section" style="width: 33%">
                    <view :class="'nav-son ' + (shownavindex == 1 ? 'active' : '')" @tap="listqy" data-nav="1">
                        <view class="content">{{ multiArray[2][multiIndex[2]] ? multiArray[2][multiIndex[2]] : '请选择' }}</view>
                        <view class="icon"></view>
                    </view>
                </view>
                <van-dropdown-menu style="width: 66%" @tap.native.stop.prevent="hidebg">
                    <van-dropdown-item @change="change2" v-model="topvalue2" :options="topoption2" />
                    <van-dropdown-item @change="change3" v-model="topvalue3" :options="topoption3" />
                </van-dropdown-menu>
            </view>
            <view class="vanTabView">
               <view :class="'vanTab vanTab1 ' + (carType == 'month' ? 'active' : '')" data-id="month" style="border-radius: 10px 0px 0px 10px" @tap="changeTab">包月车位</view>
                <view :class="'vanTab vanTab2 ' + (carType == 'temporary' ? 'active' : '')" data-id="temporary" style="border-radius: 0px 10px 10px 0px" @tap="changeTab">
                    临停车位
                </view>
            </view>
            <!-- 搜索地址列表 -->
            <view v-if="showSearch" class="search-area">
                <view :style="'height: ' + scrollHeight + 'rpx;'" v-if="addressList.length > 0">
                    <view v-for="(item, index) in addressList" :key="index">
                        <view class="search-list">
                            <view @tap="selectAddr" :data-data="item">
                                <view class="address-name">
                                    <image src="/static/pages/index2/imgs/distance2.png"></image>
                                    {{ item.title }}
                                </view>
                                <view class="addr-content">地址：{{ item.address }}</view>
                            </view>
                            <view style="float: right" @tap.stop.prevent="gotoNavigate" :data-data="item">
                                <image src="../../static/assets/img/navigation2.png" class="navigateimg route-img"></image>
                                <view class="navigatetext">路线</view>
                            </view>
                        </view>

                        <view class="middleline"></view>
                    </view>
                </view>
                <view :style="'height: ' + scrollHeight + 'rpx;text-align:center;padding-top:50rpx'" v-if="addressList.length == 0">搜索无结果</view>
            </view>
            <!-- 卡片部分 -->
            <view class="park-card2" v-else>
                <van-list 
					v-model="loading"
				    :finished="finished"
				    finished-text="没有更多了"
				    @load="onload"
					:style="'height: ' + (isScroll ? scrollHeight : '') + 'rpx;'" v-if="parkList.length > 0"
				>
					<van-cell 
					  class="park-contain" 
					  v-for="(item, index) in parkList" 
					  :key="item.unitCode"
					  :class="item.parkingAttribute == 1 && item.openProperty == 2 && item.authState != 1 ? 'park_bg' : ''">
                    <view
                        
                        @tap.stop.prevent="markerTap"
                        :data-data="item"
                        :data-parkingCode="item.parkingCode"
                        :data-unitCode="item.unitCode"
                        :data-parkingAttribute="item.parkingAttribute"
						:data-open="item.openProperty"
						:data-authState="item.authState"
						
                    >
                        <view class="park-content" :data-data="item">
                            <view>
                                <view style="display: flex; align-items: center">
                                    <!-- <image src="/assets/img/pos.png" class="tagimg"></image> -->
                                    <view class="parkname">{{ item.parkingName }}</view>

                                    <view v-if="isLogin && item.focus == 1">
                                        <image src="../../static/assets/img/follow.png" class="follow-img"></image>
                                    </view>
                                    <!-- <view class="parkrecommend" hidden="{{(filters.indexOf(item.supportBusiness,1)||filters.indexOf(item.supportBusiness,2)||filters.indexOf(item.supportBusiness,3)) ? false : true}}">
                可预约</view> -->
                                    <!-- <image wx:if='{{isLogin}}' data-item="{{item}}" data-index="{{index}}"
                src="{{item.isFocus==1?'/assets/img/nocared.png':'/assets/img/cared.png'}}" class="likeImg"
                data-isFocus="{{item.isFocus}}" data-id="{{item.parkingCode}}" catchtap="likeThisPark"></image> -->
                                </view>
                            </view>
                            <view class="card">
                                <view class="flex-content" style="margin-top: 15rpx">
                                    <view class="pop-address">{{ item.address || '暂无地址' }}</view>
                                </view>
                                <view class="flex-content rest-contain" style="margin-top: 15rpx">
                                    <view class="rest-text">共享车位:</view>
                                    <view class="rest-num">{{ item.realFreeNum || '0' }}</view>
                                </view>
                                <view class="price" v-if="item.parkingAttribute != 1">
									<view class="num" v-if="item.unitPrice / 100==0">
										免费
									</view>
                                    <view v-else class="num">
                                        {{ item.unitPrice / 100 }}
                                        <text class="yuan">元/{{ carType == 'month' ? '月' : '时' }}</text>
                                    </view>
									
                                    <!-- <view style="display: flex;">
                  <view class="menu-box-item" wx:for="{{item.productVOs}}" wx:for-item="pvos" wx:if="{{pvos.type==3}}">临停</view>
                  <view class="menu-box-item" wx:for="{{item.productVOs}}" wx:for-item="pvos" wx:if="{{pvos.type==1}}">包月</view>
                  <view class="menu-box-item" style="background: #EEF3F6;" wx:for="{{item.productVOs}}" wx:for-item="pvos" wx:if="{{pvos.type==2}}">夜间包月</view>
                </view>  -->
                                </view>
                                <view class="price" v-else style="font-family: PingFangSC-Medium; font-size: 32rpx; color: #b4b4b4; letter-spacing: 0; font-weight: 500">
                                    业主自主定价
                                </view>
                                <view class="menu-box" v-if="item.type != null" style="position: absolute; right: -152rpx; top: 60rpx">
                                    <view style="display: flex">
                                        <view
                                            class="menu-box-item"
                                            v-if="item.type == 1"
                                            style="background: #fb6b61; font-family: SourceHanSansCN-Regular; font-size: 20rpx; color: #ffffff; letter-spacing: 0; font-weight: 400"
                                        >
                                            包月
                                        </view>
                                        <view
                                            class="menu-box-item"
                                            v-if="item.type == 2"
                                            style="background: #708896; font-family: SourceHanSansCN-Regular; font-size: 20rpx; color: #ffffff; letter-spacing: 0; font-weight: 400"
                                        >
                                            夜间包月
                                        </view>
                                        <!-- <view class="menu-box-item" wx:if="{{item.type==3}}">临停</view>
              <view class="menu-box-item" wx:if="{{item.type==4}}">地面</view> -->
                                    </view>
                                </view>
                            </view>
                            <view class="rt-content">
                                <view :data-data="item" style="display: flex;">
                                    <image src="../../static/assets/img/pos.png" class="tagimg" mode="widthFix" style="width: 24rpx"></image>
                                    <view class="navigatetext" style="display: inline-block">距离{{ filters.toFix1(item.distance / 1000) }}km</view>
                                </view>
                            </view>

                            <view class="statu" style="display: flex; margin-bottom: 10rpx">
                                <view class="statuView" v-if="item.haveCharge" style="margin-right: 20rpx">
                                    <image style="width: 24rpx; position: relative; top: 7rpx; left: 5rpx; height: 24rpx;margin-right: 20rpx;" mode="widthFix" src="../../static/assets/img/elc.png" />
                                    有充电桩
                                </view>
                                <view class="statuView" v-if="item.buildType == 2" style="margin-right: 20rpx">
                                    <image style="width: 24rpx; position: relative; top: 4rpx; left: 5rpx; height: 24rpx;margin-right: 20rpx;" mode="widthFix" src="../../static/assets/img/under.png" />
                                    地下
                                </view>
                                <view class="statuView" v-if="item.buildType == 1" style="margin-right: 20rpx">
                                    <image style="width: 24rpx; position: relative; top: 4rpx; left: 5rpx; height: 24rpx;margin-right: 20rpx;" mode="widthFix" src="../../static/assets/img/ground.png" />
                                    地面
                                </view>
                                <view class="statuView" v-if="item.buildType == 3" style="">
                                    <image style="width: 24rpx; position: relative; top: 4rpx; left: 5rpx; height: 24rpx;margin-right: 20rpx;" mode="widthFix" src="../../static/assets/img/3dpark.png" />
                                    立体车库
                                </view>
								
                            </view>
                        </view>
						</view>
                    </van-cell>
					<!-- <view style="height: 200rpx;">
						
					</view> -->
					<!-- <view style="text-align: center;position: relative;" >{{allTotalElements?"数据加载完毕":"上拉加载..."}}</view> -->
                </van-list>
                <view :style="'height: ' + (isScroll ? scrollHeight : '') + 'rpx;'" v-else>
                    <van-empty image="search" description="暂无数据" v-if="!isShowLoading" />
                </view>
            </view>
        </view>
        <!-- 区域标签 -->
        <!-- 当前选择： {{multiArray[0][multiIndex[0]]}}，{{multiArray[1][multiIndex[1]]}}，{{multiArray[2][multiIndex[2]]}},{{multiArray[3][multiIndex[3]]}},{{multiArray[4][multiIndex[4]]}} -->
        <!-- 对应街道key{{chinaData[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].children[multiIndex[3]].value}} -->
        <view :class="'quyu ' + (qyopen ? 'slidown' : 'slidup') + ' ' + (qyshow ? 'disappear' : '')">
            <view class="picker2" style="display: flex; font-size: 24rpx">
                当前定位：{{ multiArray[0][multiIndex[0]] }} {{ multiArray[1][multiIndex[1]] }} {{ multiArray[2][multiIndex[2]] }} {{ multiArray[3][multiIndex[3]] }}
                {{ multiArray[4][multiIndex[4]] }}
            </view>
            <view class="qy quyu-left">
                <view
                    :class="multiIndex[0] == index ? 'current' : ''"
                    @tap="bindMultiPickerColumnChange"
                    data-column="0"
                    :data-index="index"
                    v-for="(item, index) in multiArray[0]"
                    :key="index"
                >
                    {{ item }}
                </view>
            </view>
            <view class="qy quyu-center">
                <view
                    :class="multiIndex[1] == index ? 'current2' : ''"
                    @tap="bindMultiPickerColumnChange"
                    data-column="1"
                    :data-index="index"
                    v-for="(item, index) in multiArray[1]"
                    :key="index"
                >
                    {{ item }}
                </view>
            </view>
            <view class="qy quyu-center">
                <view
                    :class="multiIndex[2] == index ? 'current2' : ''"
                    @tap="bindMultiPickerColumnChange"
                    data-column="2"
                    :data-index="index"
                    v-for="(item, index) in multiArray[2]"
                    :key="index"
                >
                    {{ item }}
                </view>
            </view>
            <view class="qy quyu-center">
                <view
                    :class="multiIndex[3] == index ? 'current2' : ''"
                    @tap="bindMultiPickerColumnChange"
                    data-column="3"
                    :data-index="index"
                    v-for="(item, index) in multiArray[3]"
                    :key="index"
                >
                    {{ item }}
                </view>
            </view>
            <view class="qy quyu-center">
                <view
                    :class="multiIndex[4] == index ? 'current2' : ''"
                    @tap="bindMultiPickerColumnChange"
                    data-column="4"
                    :data-index="index"
                    v-for="(item, index) in multiArray[4]"
                    :key="index"
                >
                    {{ item }}
                </view>
            </view>
            <view class="form-btn">
                <!-- <button class='btn-reset' bindtap='quyuEmpty'>重置</button> -->
                <button class="btn-submit" @tap="submitFilter">确定</button>
            </view>
        </view>
        <!-- <customBar /> -->
        <view :class="'fullbg ' + (isfull ? 'fullopacity' : '')" v-if="isfull && shownavindex == 1" @tap="hidebg"></view>
        <van-dialog
            id="van-dialog"
            v-model="isShowPayTip"
            title="支付提醒"
            confirm-button-text="去支付"
            cancel-button-text="稍后再看"
            confirm-button-color="#00BCAB"
            cancel-button-color="#AEAEAE"
            v-model-cancel-button="true"
			:closeOnPopstate="true"
            message="您有订单未支付，请尽快支付"
            @confirm="gotoPay($event, { tagId: 'van-dialog' })"
        />
        <van-dialog
            id="van-dialog"
            v-model="isShowAddLicense"
            title="提示"
            confirm-button-text="去添加"
            cancel-button-text="稍后添加"
            confirm-button-color="#00BCAB"
            cancel-button-color="#AEAEAE"
            v-model-cancel-button="true"
			:closeOnPopstate="true"
            message="您还没有车牌"
            @confirm="gotoAddLicense($event, { tagId: 'van-dialog' })"
        />
    </view>
</template>
<script module="filters" lang="wxs" src="../../utils/filter.wxs"></script>
<script>
// import vanRow from '@vant/weapp/row/index';
// import vanCol from '@vant/weapp/col/index';
// import vanDropdownMenu from '@vant/weapp/dropdown-menu/index';
// import vanDropdownItem from '@vant/weapp/dropdown-item/index';
// import vanToast from '@vant/weapp/toast/index';
import user from '../user/index';
// import vanEmpty from '@vant/weapp/empty/index';
// index.js
// 获取应用实例
var cityData = require('../../utils/city.js'); //引入自己定义的深圳地铁区域及号线数据信息

const app = getApp();
import util from './../../utils/util.js';
import api from './../../utils/api.js';
// import Toast from '@vant/weapp/toast/toast';
import amapFile from './../../utils/amap-wx.js'; // import config from '../../utils/config';
import { Dialog } from 'vant';

export default {
    components: {
        // vanRow,
        // vanCol,
        // vanDropdownMenu,
        // vanDropdownItem,
        // vanToast,
        // user,
        // vanEmpty
    },
    data() {
        return {
            //区域联动开始
            cityIndex: [0, 0, 0, 0, 0],

            content: [],
            isFocus: '',
            firstLoad: true,
            qyopen: false,

            //点击地铁区域筛选滑动弹窗显示效果，默认不显示
            qyshow: true,

            //用户点击闭关区域的弹窗设置，默认不显示
            isfull: false,

            cityleft: cityData.getCity(),

            //获取地铁区域的下拉框筛选项内容
            citycenter1: {},

            //选择地铁区域左边筛选框后的显示的中间内容部分1
            citycenter2: {},

            //选择地铁区域左边筛选框后的显示的中间内容部分2
            citycenter3: {},

            //选择地铁区域左边筛选框后的显示的中间内容部分3
            cityright: {},

            //选择地铁区域的中间内容部分后显示的右边内容
            select1: '区域',

            //地铁区域选中后的第二个子菜单，默认显示地铁下的子菜单
            select2: '',

            //地铁区域选择部分的中间1
            select3: '',

            //地铁区域选择部分的中间2
            select4: '',

            //地铁区域选择部分的中间3
            select5: '',

            //地铁区域选择部分的右边
            searchName: '',

            personUnionId: '',

            //用户unionId，用于筛选关注的车场
            shownavindex: '',

            //区域联动结束
            buildType: '',
			
			//邻里停停车场类型
			parkingAttribute:'',
			
            //建筑类型,1地面停车场；2地下停车库；3地上停车楼(立体车库，大型车慎选)
            haveCharge: '',

            //是否有充电桩，1是0否
            parkType: 2,

            //0全部 1推荐  2临停 3包整月 4包夜
            multiArray: [[], [], [], [], []],

            multiIndex: [0, 0, 0, 0, 0],
            topvalue1: '杭州',
            topvalue2: '0',
            topvalue3: '0',

            topoption1: [
                {
                    text: '杭州',
                    value: '杭州'
                }
            ],

            topoption2: [
                {
                    text: '类型',
                    value: '0'
                },
                {
                    text: '我的关注',
                    value: '1'
                },
				{
					text:'机关企事业单位',
					value:'2'
				},
				{
					text:'小区',
					value:'3'
				},
				{
					text:'商业',
					value:'4'
				}
                // {
                //     text: '地下',
                //     value: '2'
                // },
                // {
                //     text: '地面',
                //     value: '3'
                // },
                // {
                //     text: '立体车库',
                //     value: '4'
                // },
                // {
                //     text: '有充电桩',
                //     value: '5'
                // }
            ],

            topoption3: [
                {
                    text: '距离优先',
                    value: '0'
                }
            ],

            isLogin: 0,

            //0未登录 1已登录
            option1: [
                {
                    text: '全部',
                    value: 0
                },
                {
                    text: '推荐',
                    value: 1
                },
                {
                    text: '临停预约',
                    value: 2
                },
                {
                    text: '包整月',
                    value: 3
                },
                {
                    text: '夜间包月',
                    value: 4
                }
            ],

            bannerUrls: [],
            imgheights: '',
            longitude: '',
            latitude: '',
            autoSearch: '',
            isSearch: 0,
            value1: 0,
            startY: 0,

            //滑动开始y轴位置
            lastY: 0,

            //滑动开始y轴位置
            parkList: [],

            parkListLike: [],
            markers: [],
            showPop: false,
            allParkFlag: true,
            center: [120.140812, 30.176627],
            timer: null,
            marginTopmenuBtn: uni.getMenuButtonBoundingClientRect(),
            popData: [],
            showMonth: false,

            //是否支持包月
            showReserve: false,

            //是否支持预约
            hideReleasepop: true,

            btmTop: '890',
            showUser: false,
            isScroll: false,
            scrollHeight: '',
            showSearch: false,

            //是否展示搜索列表
            addressList: [],
			weixin:uni.getStorageSync('weixin'),
            screenHeightRPX: '',

            //屏幕高度rpx
            mapHeight: '650',

            isAndroid: false,
            isShowPayTip: false,

            //是否提示未支付订单
            showDropdown: false,

            //是否下拉
            isSearching: false,

            //是否正在搜索--显示右侧搜索
            showBack: false,

            //输入框聚焦时的返回按钮
            gotopayType: '',

            weather: {},

            //天气信息
            pageNumber: 1,

            controlNo: '',
            isShowAddLicense: false,
            isShowLoading: false,

            //当前为加载状态时不可展示‘无数据’
            carType: 'month',

            chinaData: '',
            isFixSpaceNumer: '',
            citycenter: '',
			uiStyle:1,
			loading: false,
		    finished: false,
        };
    },
    onLoad(options) {
        let that = this;
        this.uiStyle = uni.getStorageSync('uiStyle') || 1

        if (options.searchName) {
            this.setData({
                searchName: options.searchName
            });
        }

        if (options.isSearching) {
            this.setData({
                isSearching: options.isSearching
            });
        }

        uni.showLoading({
            title: '加载中'
        });
        this.setData({
            isShowLoading: true
        });
        that.getSiteData();
        uni.getSystemInfo({
            success: (res) => {
                // console.log(res)
                this.setData({
                    scrollHeight: res.screenHeight * (750 / res.windowWidth) - 350 - (res.platform == 'android' ? 70 : 120),
                    //再减去50的底部tab
                    screenHeightRPX: res.screenHeight * (750 / res.windowWidth),
                    isAndroid: res.platform == 'android' ? true : false
                });
            }
        });

        if (uni.getStorageSync('AUTHORIZATION')) {
            this.setData({
                isLogin: 1
            });
            this.isWaitingtopay();
        }

        that.getTrafficControl();
        setTimeout(function () {
            that.getWeather();
        }, 31000); // 处理关于分享的用户unionId

        if (options.shareId && options.shareId != '') {
            uni.setStorageSync('shareId', options.shareId);
        }

        if (options.activityCode && options.activityCode != '') {
            uni.setStorageSync('activityCode', options.activityCode);
        }
    },
    onHide() {
        this.setData({
            searchName: ''
        });
        clearInterval(this.timer);
    },
    onShow() {
        // this.setData({
        //   searchName: ""
        // })
        // tabbar不支持url后带参数 ，只能存一下
        if (uni.getStorageSync('searchHistory') && uni.getStorageSync('searchHistory')[0].name && uni.getStorageSync('isSearching')) {
            this.setData({
                searchName: uni.getStorageSync('searchHistory')[0].name
            });
            console.log(this.searchName);
            this.getCurLocation();
        } else {
            this.clearInput2(); // this.getCurLocation()

            this.setData({
                center: [this.longitude, this.latitude]
            });
        }

        this.setData({
            showPop: false
        }); // 存储当前页面-登陆后跳转至登录前页面

        const page = getCurrentPages(); // console.log(page[0].route)

        uni.setStorageSync('lastPagePath', '/' + page[0].route);

        if (uni.getStorageSync('AUTHORIZATION')) {
            this.setData({
                isLogin: 1
            });
        }
    },
    //上拉刷新
    onReachBottom(e) {
        console.log(e);
        let num = this.pageNumber + 1;
        this.setData(
            {
                pageNumber: num
            },
            () => this.getParklist()
        );
    },
    methods: {
		onload(){
			this.loading = true
			if(this.parkList.length==0){
				this.pageNumber=1
			}else{
				this.pageNumber=this.pageNumber+1
			}
			this.getParklist()
			
		},
		setData:function(obj){
					let that = this;    
					let keys = [];    
					let val,data;    
					Object.keys(obj).forEach(function(key){    
					 keys = key.split('.');    
					 val = obj[key];    
					 data = that.$data;    
					 keys.forEach(function(key2,index){    
						 if(index+1 == keys.length){    
							 that.$set(data,key2,val);    
						 }else{    
							 if(!data[key2]){    
								that.$set(data,key2,{});    
							 }    
						 }    
						 data = data[key2];    
					 })    
					});    
					},
        changeTab: function (e) {
            console.log(e.currentTarget.dataset.id);
            this.setData({
                carType: e.currentTarget.dataset.id
            });
            this.getParklist();
        },

        bindMultiPickerChange: function (e) {
            this.getParklist();
            this.getMaplist();
        },

        bindMultiPickerColumnChange: function (e) {
			console.log("bindMultiPickerColumnChange")
            var move = e.target.dataset.index;
            var index = e.target.dataset.column;
            var value = move;

            if (index == 0) {
				this.multiIndex=[value, 0, 0, 0, 0]
                // this.setData({
                //     multiIndex: 
                // });
                this.getCity();
            }

            if (index == 1) {
				this.multiIndex[1]=value;
				this.multiIndex[2]=0;
				this.multiIndex[3]=0;
				this.multiIndex[4]=0;
                // this.setData({
                //     'multiIndex[1]': value,
                //     'multiIndex[2]': 0,
                //     'multiIndex[3]': 0,
                //     'multiIndex[4]': 0
                // });
                this.getXian();
            }

            if (index == 2) {
				
				this.multiIndex[2]=value;
				this.multiIndex[3]=0;
				this.multiIndex[4]=0;
                // this.setData({
                //     'multiIndex[2]': value,
                //     'multiIndex[3]': 0,
                //     'multiIndex[4]': 0
                // });
                this.getZhen();
            }

            if (index == 3) {
				this.multiIndex[3]=value;
				this.multiIndex[4]=0;
                // this.setData({
                //     'multiIndex[3]': value,
                //     'multiIndex[4]': 0
                // });
                this.getShequ();
            }

            if (index == 4) {
				this.multiIndex[4]=value;
				
                // this.setData({
                //     'multiIndex[4]': value
                // });
            }
			this.$forceUpdate();
        },

        getSiteData: function () {
            var that = this;
            let param = {
                codeOrId: 'code'
            };
            uni.showLoading({
                title: '加载中...'
            });
            util.request(api.queryOrganizeProjectTree, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    uni.hideLoading({
                        success: (res) => {}
                    });

                    if (res.success) {
                        var chinaData = [res.data]; // console.log(chinaData)

                        this.chinaData = chinaData;
                        var sheng = []; //  设置省数组

                        for (var i = 0; i < chinaData.length; i++) {
                            sheng.push(chinaData[i].title);
                        }
						this.multiArray[0]=sheng;
						this.chinaData=chinaData;
                        // this.setData({
                        //     chinaData: chinaData,
                        //     'multiArray[0]': sheng
                        // });
                        that.getCity(); // 得到市
                    } else {
                        Toast(res.msg || '接口出错了，请稍后再试');
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: err || '接口出错了，请稍后再试',
                        icon: 'none'
                    });
                });
        },

        getCity: function () {
            //  得到市
            var shengNum = this.multiIndex ? this.multiIndex[0] : 0;
            var chinaData = this.chinaData;
            var cityData = chinaData[shengNum].children ? chinaData[shengNum].children : [];
            var city = [];

            for (var i = 0; i < cityData.length; i++) {
                city.push(cityData[i].title);
            }
			this.multiArray[1]=city;
            // this.setData({
            //     'multiArray[1]': city
            // });
            this.getXian();
        },

        getXian: function (e) {
            //  得到县
            var shengNum = this.multiIndex ? this.multiIndex[0] : 0;
            var cityNum = this.multiIndex ? this.multiIndex[1] : 0;
            var chinaData = this.chinaData;
            var xianData = chinaData[shengNum].children[cityNum] ? chinaData[shengNum].children[cityNum].children : [];
            var xian = [];

            for (var i = 0; i < xianData.length; i++) {
                xian.push(xianData[i].title);
            }
			this.multiArray[2]=xian;
            // this.setData({
            //     'multiArray[2]': xian
            // });
            this.getZhen();
        },

        getZhen: function () {
            //  得到镇
            var shengNum = this.multiIndex ? this.multiIndex[0] : 0;
            var cityNum = this.multiIndex ? this.multiIndex[1] : 0;
            var xianNum = this.multiIndex ? this.multiIndex[2] : 0;
            var chinaData = this.chinaData;
            var zhenData = chinaData[shengNum].children[cityNum].children[xianNum] ? chinaData[shengNum].children[cityNum].children[xianNum].children : [];
            var zhen = [];

            for (var i = 0; i < zhenData.length; i++) {
                zhen.push(zhenData[i].title);
            }
			this.multiArray[3]=zhen;
            // this.setData({
            //     'multiArray[3]': zhen
            // }); // console.log(this.data.multiArray)
			
            this.getShequ();

        },

        getShequ: function () {
            //  得到社区
            var shengNum = this.multiIndex ? this.multiIndex[0] : 0;
            var cityNum = this.multiIndex ? this.multiIndex[1] : 0;
            var xianNum = this.multiIndex ? this.multiIndex[2] : 0;
            var shequNum = this.multiIndex ? this.multiIndex[3] : 0;
            var chinaData = this.chinaData;

            if (
                chinaData[shengNum].children[cityNum].children[xianNum] &&
                chinaData[shengNum].children[cityNum].children[xianNum].children &&
                chinaData[shengNum].children[cityNum].children[xianNum].children[shequNum]
            ) {
                var shquData = chinaData[shengNum].children[cityNum].children[xianNum].children[shequNum].children;
            } else {
                var shquData = [];
            }

            var shequ = [];

            for (var i = 0; i < shquData.length; i++) {
                shequ.push(shquData[i].title);
            }
			
			this.multiArray[4]=shequ;

            // this.setData({
            //     'multiArray[4]': shequ
            // }); // if(this.data.firstLoad){
            //   this.getCurLocation();
            //   this.setData({
            //     "firstLoad" : false
            //   })
            // }

            if (this.isSearching) {
                this.getCurLocation();
            }
        },

        change1() {},

        change2( detail ) {
            const value = detail; // console.log(value)

            this.setData({
                personUnionId: '',
                buildType: '',
                haveCharge: '',
                isFocus: '',
				parkingAttribute:''
            });

            if (value == 0) {
                //全部
                this.getParklist();
            } else if (value == 1) {
                //关注
                this.setData({
                    isFocus: '1'
                });
                this.getParklist();
            } else if(value==2){
				//政府机关单位
				this.setData({
					parkingAttribute:'4'
				})
				this.getParklist()
			} else if(value==3){
				this.setData({
					parkingAttribute:'1'
				})
				this.getParklist()
			} else if(value==4){
				this.setData({
					parkingAttribute:'3'
				})
				this.getParklist()
			}
			
			// else if (value == 2) {
   //              //地下
   //              this.setData({
   //                  buildType: 2
   //              });
   //              this.getParklist();
   //          } else if (value == 3) {
   //              //地面
   //              this.setData({
   //                  buildType: 1
   //              });
   //              this.getParklist();
   //          } else if (value == 4) {
   //              //立体车库
   //              this.setData({
   //                  buildType: 3
   //              });
   //              this.getParklist();
   //          } else if (value == 5) {
   //              //是否有充电桩
   //              this.setData({
   //                  haveCharge: 1
   //              });
   //              this.getParklist();
   //          }
        },

        change3() {},

        queryOrganizeProjectTree() {
            let param = {
                codeOrId: 'code'
            };
            uni.showLoading({
                title: '加载中...'
            });
            util.request(api.queryOrganizeProjectTree, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    uni.hideLoading({
                        success: (res) => {}
                    });
                    this.setData({
                        isShowLoading: false
                    });

                    if (res.success) {
                    } else {
                        Toast(res.msg || '接口出错了，请稍后再试');
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: err || '接口出错了，请稍后再试',
                        icon: 'none'
                    });
                });
        },

        changeDrop(e) {
            this.setData({
                value1: e.detail,
                showDropdown: false
            });
            this.getParklist();
        },

        likeThisPark(event) {
            //关注车场
            let that = this;

            if (event.currentTarget.dataset.id) {
                console.log('即将关注或取消id为：' + event.currentTarget.dataset.id);
                let type = event.currentTarget.dataset.isfocus == 1 ? 2 : 1; //1关注，2取消关注

                util.request(api.addOrUpdateFocus + '?unionId=' + uni.getStorageSync('unionId') + '&parkingCode=' + event.currentTarget.dataset.id + '&type=' + type, 'get')
                    .then((res) => {
                        if (res.success) {
                            if (event.currentTarget.dataset.isfocus == 1) {
                                //取消关注成功
                                event.currentTarget.dataset.item.isFocus = 0;
                                var _popData = that.popData;
                                _popData[event.currentTarget.dataset.index] = event.currentTarget.dataset.item;
                                that.setData({
                                    popData: _popData
                                });
                                uni.showToast({
                                    title: '取消关注成功'
                                });
                                this.getParklist();
                                this.getMaplist();
                            } else if (event.currentTarget.dataset.isfocus == 0) {
                                //添加关注成功
                                event.currentTarget.dataset.item.isFocus = 1;
                                var _popData = that.popData;
                                _popData[event.currentTarget.dataset.index] = event.currentTarget.dataset.item;
                                that.setData({
                                    popData: _popData
                                });
                                uni.showToast({
                                    title: '关注成功'
                                });
                                uni.requestSubscribeMessage({
                                    tmplIds: ['G-qqlo3c5ARPqg9lPCnCrSUxAEgZ8bPfrEpd0UVE-8o'],

                                    success(sus) {},

                                    fail(err) {}
                                });
                                this.getParklist();
                                this.getMaplist();
                            }
                        }
                    })
                    .catch((err) => {
                        console.log(err);
                    });
            }
        },

        //获取关注停车场列表数据
        getParklistLike() {
            if (!uni.getStorageSync('unionId') || !this.latitude) {
                return;
            }

            let param = {
                unionId: uni.getStorageSync('unionId'),
                mapy: this.latitude,
                mapx: this.longitude,
                contentSearch: this.isSearch,
                type: this.value1,
                pageNumber: 1,
                pageSize: 40
            };
            util.request(api.myFocus, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    uni.hideLoading({
                        success: (res) => {}
                    });
                    this.setData({
                        isShowLoading: false
                    });

                    if (res.success) {
                        let list = res.data.content;

                        if (list) {
                            list.map((item) => {
                                if (item.productVOs) {
                                    item.productVOs.map((i) => {
                                        if (i.type == 3) {
                                            item.tempReserveProduct = i;
                                        } else if (i.type == 4) {
                                            item.tempProduct = i;
                                        }
                                    });
                                }
                            });
                        } // list = list.filter(function (item) {
                        //   return item.distance < 1000
                        // })

                        this.setData({
                            parkList: list ? list : []
                        }); // console.log(this.data.parkList)
                    } else {
                        Toast(res.msg || '接口出错了，请稍后再试');
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: err || '接口出错了，请稍后再试',
                        icon: 'none'
                    });
                });
        },

        //获取停车场列表数据
        getParklist(focus) {
            //focus表示是否查询关注
            var that = this;
            var organizeUnionId = '';

            if (this.chinaData && this.chinaData[this.multiIndex[0]]) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].value;
                } catch (error) {}
            }

            if (this.chinaData && this.chinaData[this.multiIndex[0]] && this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]]) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]]
            ) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]]
            ) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].children[this.multiIndex[4]]
            ) {
                try {
                    organizeUnionId =
                        this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].children[this.multiIndex[4]]
                            .value;
                } catch (error) {}
            }

            console.log('organizeUnionId:' + organizeUnionId);

            if (!organizeUnionId) {
                setTimeout(() => {
                    that.getParklist(1);
                }, 800);
                return;
            }

            let param = {
                mapy: this.latitude,
                mapx: this.longitude,
                type: this.carType == 'month' ? '2' : '1',
                parkingNameLike: this.searchName ? this.searchName : '',
                pageNo: 1,
                personUnionId: uni.getStorageSync('unionId'),
                buildType: this.buildType,
                //建筑类型,1地面停车场；2地下停车库；3地上停车楼(立体车库，大型车慎选)
                haveCharge: this.haveCharge,
                //是否有充电桩，1是0否
                pageSize: 10 * this.pageNumber,
                isFocus: this.isFocus ? '1' : '',
                // distance:1000000,
                organizeUnionId: organizeUnionId,
				parkingAttribute:this.parkingAttribute
            }; // this.setData({
            //   searchName:""
            // })

            uni.showLoading({
                title: '加载中...'
            });
            this.setData({
                isShowLoading: true
            });
            util.request(api.parkingList, param, 'POST')
                .then((res) => {
                    uni.hideLoading({
                        success: (res) => {}
                    });
                    this.setData({
                        isShowLoading: false
                    });

                    if (res.success) {
                        let list = res.data.content;

                        if (list) {
                            list.map((item) => {
                                if (item.productVOs) {
                                    item.productVOs.map((i) => {
                                        if (i.type == 3) {
                                            item.tempReserveProduct = i;
                                        } else if (i.type == 4) {
                                            item.tempProduct = i;
                                        }
                                    });
                                }
                            });
                        }
						var listall = []
						if(uni.getStorageSync('weixin') == 3 || uni.getStorageSync('weixin') == 4){
							list.map((res,ind)=>{
								if(res.parkingName == '奥体实验小学'){
									list.splice(1,ind)
								}
							})
							list.forEach(res=>{
								if(res.parkingName != '滨和中小学停车场'){
									listall.push(res)
								}
							})
						}else{
							listall = list
						}
                        this.setData({
                            parkList: listall
                        });
						this.loading=false
						if(res.data.totalElements<=res.data.size){
							this.finished = true
						}
                    } else {
                        Toast(res.msg || '接口出错了，请稍后再试');
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: err || '接口出错了，请稍后再试',
                        icon: 'none'
                    });
                });
        },

        //获取地图撒点数据
        getMaplist() {
            var organizeUnionId = '';

            if (this.chinaData && this.chinaData[this.multiIndex[0]]) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].value;
                } catch (error) {}
            }

            if (this.chinaData && this.chinaData[this.multiIndex[0]] && this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]]) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]]
            ) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]]
            ) {
                try {
                    organizeUnionId = this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].value;
                } catch (error) {}
            }

            if (
                this.chinaData &&
                this.chinaData[this.multiIndex[0]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]] &&
                this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].children[this.multiIndex[4]]
            ) {
                try {
                    organizeUnionId =
                        this.chinaData[this.multiIndex[0]].children[this.multiIndex[1]].children[this.multiIndex[2]].children[this.multiIndex[3]].children[this.multiIndex[4]]
                            .value;
                } catch (error) {}
            }

            let param = {
                mapy: this.latitude,
                mapx: this.longitude // organizeUnionId:organizeUnionId
                // allowOrder:1
            };

            if (uni.getStorageSync('unionId')) {
                param.unionId = uni.getStorageSync('unionId');
            }

            util.request(api.getMaplist, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    // wx.hideLoading({
                    //   success: (res) => {},
                    // })
                    // this.setData({isShowLoading:false})
                    var _markerList = [];

                    for (var i = 0; i < markerList.length; i++) {
                        for (var j = 0; j < markerList[i].mapAnalysisDBVOs.length; j++) {
                            _markerList.push(Object.assign({}, markerList[i], markerList[i].mapAnalysisDBVOs[j]));
                        }
                    }

                    markerList = _markerList;
                    console.log(_markerList);

                    for (var key in markerList) {
                        var marker = markerList[key];
                        marker.id = Number(key);
                        marker.latitude = Number(marker.gmapY);
                        marker.longitude = Number(marker.gmapX);
                        marker.width = 52;
                        marker.height = 62;
                        marker.label = {
                            content: String(marker.realFreeNum) || '0',
                            fontSize: 13,
                            anchorX: this.isAndroid ? -(0.5 * (marker.realFreeNum.toString().length * 8)) : 0,
                            anchorY: -43,
                            textAlign: 'center'
                        };

                        if (marker.notOpenToALLParkingNum > 0 && marker.openToALLParkingNum == 0) {
                            // marker.callout = {
                            //   content: "限小区居民",
                            //   color: "#FFFFFF",
                            //   fontSize: 10,
                            //   padding: 5,
                            //   borderRadius: 18,
                            //   bgColor: "#AEAEAE",
                            //   display: "ALWAYS",
                            //   textAlign: "center",
                            //   anchorY:6
                            // };
                        } else if (marker.notOpenToALLParkingNum > 0) {
                            // marker.callout = {
                            //   content: "部分限小区居民",
                            //   color: "#FFFFFF",
                            //   fontSize: 10,
                            //   padding: 5,
                            //   borderRadius: 18,
                            //   bgColor: "#AEAEAE",
                            //   display: "ALWAYS",
                            //   textAlign: "center",
                            //   anchorY:6
                            // };
                        }

                        if (marker.authNumber == 0 && marker.openToALLParkingNum == 0) {
                            marker.iconPath = '../../static/assets/img/pointGray.png';
                            marker.label.color = '#A8A8A8';
                        } else {
                            marker.iconPath = '../../static/assets/img/pointGreen.png';
                            marker.label.color = '#00BCAB';
                        }

                        let list = marker.mapAnalysisDBVOs;

                        if (list) {
                            list.map((item) => {
                                if (item.productVOs) {
                                    item.productVOs.map((i) => {
                                        if (i.type == 3) {
                                            item.tempReserveProduct = i;
                                        } else if (i.type == 4) {
                                            item.tempProduct = i;
                                        }
                                    });
                                }
                            });
                        }

                        list = list.filter(function (item) {
                            return item.distance < 1000;
                        });
                        this.setData({
                            markers: markerList
                        });
                    }

                    if (this.isSearching) {
                        this.selectAddr(uni.getStorageSync('searchHistory')[0]);
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: err || '接口出错了，请稍后再试',
                        icon: 'none'
                    });
                });
        },

        /**
         * 每隔30秒地图刷新方法
         */
        refreshMap() {
            let that = this;
            var i = setInterval(() => {
                that.getMaplist();
            }, 30000);
            this.setData({
                timer: i
            });
        },

        // 事件处理函数
        bindViewTap() {
            uni.navigateTo({
                url: '../logs/logs'
            });
        },

        // 车位引导图
        toNavigateYd(e) {
            // console.log(e.currentTarget.dataset)
            uni.navigateTo({
                url:
                    '../parkImgNav/index?parkingCode=' +
                    e.currentTarget.dataset.id +
                    '&guidePicture=' +
                    e.currentTarget.dataset.guidepicture +
                    '&name=' +
                    e.currentTarget.dataset.name
            });
        },

        /**
         * 获取用户当前位置,获取后调用接口数据
         *
         */
        getCurLocation() {
            uni.showLoading({
                title: '加载中'
            });
            this.setData({
                isShowLoading: true
            });
            let that = this;

            if (this.latitude) {
                uni.showLoading({
                    title: '加载中...'
                });
                this.setData({
                    isShowLoading: true
                });
                this.getMaplist();
                this.getParklist();
                return;
            }
			console.log("uni.getLocation")
			
            uni.getLocation({
                type: 'gcj02',
                success: (res) => {
                    console.log('成功获取:' + res);
                    this.setData({
                        latitude: res.latitude,
                        //res.latitude 30.175580
                        longitude: res.longitude //res.longitude 120.141186
                    });
                    this.setData({
                        center: [this.longitude, this.latitude]
                    });
                    this.setData({
                        allParkFlag: true
                    }); // wx.hideLoading({
                    //   success: (res) => {},
                    // })
                    // if(!this.data.isSearching){
                    //   this.getParklist(1);
                    // }

                    uni.showLoading({
                        title: '加载中...'
                    });
                    this.setData({
                        isShowLoading: true
                    });
                    this.getMaplist();
                    this.getParklist();
                },

                fail(e) {
					// alert(2)
					if (navigator.geolocation) {
					    uni.showModal({
					        title: '温馨提示',
					        content: '您已拒绝定位,请开启',
					        confirmText: '去设置',
					        success(res) {
					            if (res.confirm) {
					                //打开授权设置
					                that.openSetting();
					            }
					        }
					    });
					} else {
					    uni.showToast({
					    	title:'该浏览器暂不支持定位，请更换浏览器后重试'
					    })
					}
					// console.log(e)
     //                uni.getSetting({
     //                    success(result) {
     //                        // 先获取用户是否已开启定位权限
     //                        let setting = result.authSetting;
     //                        let setLocation = 'scope.userLocation';
     //                        if (!setting[setLocation]) {
     //                            // 定位权限未开启，引导设置
     //                            uni.showModal({
     //                                title: '温馨提示',
     //                                content: '您已拒绝定位,请开启',
     //                                confirmText: '去设置',
     //                                success(res) {
     //                                    if (res.confirm) {
     //                                        //打开授权设置
     //                                        that.openSetting();
     //                                    }
     //                                }
     //                            });
     //                        }
     //                    }
     //                });
                }
            });
			console.log("uni.getLocation2")
        },

        /**
         * 点击地图上定位按钮回到起始位置
         */
        moveTolocation: function () {
            var mapCtx = uni.createMapContext('mymap'); //wxml中map标签的id值

            mapCtx.moveToLocation();
            this.getCurLocation();
            this.setData({
                isSearching: false,
                isSearch: 0
            });
        },

        /**
         * 点击跳转发布车位
         */
        releasePark() {
            if (uni.getStorageSync('AUTHORIZATION')) {
                util.request(api.myUnitList + '?unionId=' + uni.getStorageSync('unionId'), 'get').then((res) => {
                    if (res.code == 0) {
                        if (res.data.length > 0) {
                            uni.navigateTo({
                                url: '../setParking1/index'
                            });
                        } else {
                            // wx.navigateTo({
                            //   url: "../community1/index"
                            // });
                            uni.switchTab({
                                url: '../community1/index'
                            });
                        }
                    } else {
                        Toast(res.msg || '接口出错了，请稍后再试');
                    }
                });
            } else {
                uni.navigateTo({
                    url: '../login/index'
                });
            }
        },

        /**
         * 点击标记点
         */
        markerTap(e) {
            var parkingcode = e.currentTarget.dataset.parkingcode;
            var parkingAttribute = e.currentTarget.dataset.data.parkingAttribute;
			var openProperty = e.currentTarget.dataset.data.openProperty
			var authState = e.currentTarget.dataset.data.authState
			var parkName = e.currentTarget.dataset.data.parkingName
			// var parkName = '一城停车场'
			if(parkingAttribute == 1 && openProperty == 2 && authState != 1){
				uni.showToast({
					title:'该小区仅对居民内部开放',
					icon:'none'
				})
			}else{
				if(parkName == '一城停车场'){
					var _this = this
					uni.showModal({
						title:'提示',
						content:`欢迎您选择一城停车场，本车场为机械式停车库，选择包月服务时请留意以下注意事项：
								1、车位为不固定机械车位，在包月前请确认您的车辆尺寸（长*宽*高）不超过5200mm*1900mm*1550mm（中小型轿车），车重不超过2350kg。
								2、停车时为正向驶入车库，停放到位后，请您拉好手刹、关好车窗、车门，收起后视镜，确认熄火后下车并立即离开车库。
								3、车主应遵守机械车库对车辆限长、限宽、限高、限重的停放要求，若强行停放造成车辆、机械车库或建筑设施受损的，由肇事者自行承担赔偿。
								4、本车场为24小时人工值守车场，存取车辆务必由现场工作人员进行操作，若车主擅自操作发生事故，车场实际运营方将追究相应责任。`,
						success(res) {
							if(res.confirm){
								if (parkingcode && parkingAttribute == 1) {
								    //先暂时写死为小区跳转
								    uni.navigateTo({
								        url: '../newParklist/newParklist?parkingcode=' + parkingcode + '&active=' + (_this.carType == 'month' ? '1' : '0')
								    });
								    return;
								}
								if (_this.carType == 'month') {
								    //包月
								    _this.monthlyParking(e);
								} else if (_this.carType == 'temporary') {
								    //临停
								    _this.tempParking(e);
								}
							}
						}		
					})
				}else {
					if (parkingcode && parkingAttribute == 1) {
					    //先暂时写死为小区跳转
					    uni.navigateTo({
					        url: '../newParklist/newParklist?parkingcode=' + parkingcode + '&active=' + (this.carType == 'month' ? '1' : '0')
					    });
					    return;
					}
					if (this.carType == 'month') {
					    //包月
					    this.monthlyParking(e);
					} else if (this.carType == 'temporary') {
					    //临停
					    this.tempParking(e);
					}
				}
				
			}
            
        },

        /**关闭底部弹窗 */
        closePop() {
            this.setData({
                showPop: false
            });

            if (uni.getStorageSync('AUTHORIZATION')) {
                this.setData({
                    isLogin: 1
                });
                this.getParklist();
            }
        },

        //到这去
        gotoHere(e) {
            this.setLog('GO_HERE');
            const data = e.currentTarget.dataset.data;
            let param = {
                latitude: Number(data.gmapY),
                longitude: Number(data.gmapX),
                address: data.address
            };
            this.onRunApi(param);
        },

        goAllParking() {
            // console.log("goAllParking");
            this.setData({
                allParkFlag: true
            });
            this.getParklist();
        },

        /**唤起导航 */
        toNavigate(e) {
            this.setLog('NAVIGATION');
            const data = e.currentTarget.dataset.data;
            let param = {
                latitude: Number(data.gmapY),
                longitude: Number(data.gmapX),
                address: data.address
            };
            this.onRunApi(param);
        },

        //点击整个卡片 需判断是否支持临停，或包月 或都支持
        buyParking(e) {
            this.setLog('PARKING_SPACE_LIST');
            const data = e.currentTarget.dataset.data;

            if (data.supportBusiness.indexOf('0') > -1 || data.supportBusiness == '') {
                Toast('抱歉，该车场未开通停车业务');
            } else if (data.supportBusiness.indexOf('1') > -1) {
                this.tempParking(e);
            } else {
                this.monthlyParking(e);
            }
        },

        /**临停预约 */
        tempParking(e) {
            this.setLog('MONTHLY_SUBSCRIPTION_AND_RESERVATION');
            const data = e.currentTarget.dataset.data; // console.log(data);

            const isLogin = this.getIsLogin();

            if (isLogin) {
                if (data.openProperty == 2 && data.isAuth == 2) {
					uni.showToast({
					    title: '抱歉，共享车位仅限本小区居民预约',
					    icon: 'none'
					});
                } else if (data.supportBusiness.indexOf('1') < 0) {
					uni.showToast({
					    title: '抱歉，该车场不支持临停预约业务',
					    icon: 'none'
					});
                } else if (uni.getStorageSync('plateNos') == '') {
                    this.setData({
                        isShowAddLicense: true
                    });
                } else {
                    let param = {
                        parkingCode: data.parkingCode
                    };
					// console.log(e.currentTarget.dataset.data)
					// return
                    uni.navigateTo({
                        url:
                            '../newBookpark/newBookpark?param=' +
                            data.parkingCode +
                            '&lltParkingInfoType=' +
                            data.lltParkingInfoType +
                            '&focus=' +
                            data.focus +
                            '&type=' +
                            data.type +
                            '&spaceNoId=' +
                            data.id + 
							'&realFreeNum='+
							data.realFreeNum
                    });
                }
            } else {
                Toast('您未登录，请先登录');
                setTimeout(() => {
                    uni.navigateTo({
                        url: '../login/index'
                    });
                }, 2000);
            }
        },

        /**包月 */
        monthlyParking(e) {
            this.setLog('MONTHLY_SUBSCRIPTION');
            const data = e.currentTarget.dataset.data;
            const isLogin = this.getIsLogin();
			console.log(data)
            if (isLogin) {
                if (uni.getStorageSync('plateNos') == '') {
                    this.setData({
                        isShowAddLicense: true
                    });
                } else {
                    if (data.lltParkingInfoType == 2) {
                        console.log(data);
                        uni.navigateTo({
                            url:
                                '../newMonthpark/newMonthpark?param=' +
                                data.parkingCode +
                                '&isAlipay=' +
                                data.isAlipay +
                                '&isWechat=' +
                                data.isWechat +
                                '&lltParkingInfoType=' +
                                data.lltParkingInfoType +
                                '&focus=' +
                                data.focus +
                                '&type=' +
                                data.type +
                                '&spaceNoId=' +
                                data.id //+data.lltParkingInfoType
								
                        });
                        return;
                    }

                    let param = {
                        parkingCode: data.parkingCode
                    };
                    uni.navigateTo({
                        url:
                            '../newMonthpark/newMonthpark?param=' +
                            data.parkingCode +
                            '&isAlipay=' +
                            data.isAlipay +
                            '&isWechat=' +
                            data.isWechat +
                            '&lltParkingInfoType=' +
                            data.lltParkingInfoType +
                            '&focus=' +
                            data.focus +
                            '&type=' +
                            data.type +
                            '&spaceNoId=' +
                            data.id + //+data.lltParkingInfoType
							'&realFreeNum='+
							data.realFreeNum
                    });
                }
            } else {
                Toast('您未登录，请先登录');
                setTimeout(() => {
                    uni.navigateTo({
                        url: '../login/index'
                    });
                }, 2000);
            }
        },

        /**
         * 判断停车场里是否有车位,有则是否是固定的
         */
        isHasParkinglot(e) {
            let param = {
                parkingCode: e
            };
            util.request(api.isHasParklot, param, 'POST', 'application/x-www-form-urlencoded').then((res) => {
                if (res.success) {
                    this.setData({
                        isFixSpaceNumer: res.data
                    });
                } else {
                    Toast(res.msg || '接口出错了，请稍后再试');
                }
            });
        },

        gotoPersonInfo() {
            // 判断是否登录，已登录进入个人中心；未登录进入注册登录页面
            if (uni.getStorageSync('AUTHORIZATION')) {
                this.setData({
                    showUser: true
                });
            } else {
                uni.navigateTo({
                    url: '../login/index'
                });
            }
        },

        onCloseUser() {
            this.setData({
                showUser: false
            });
        },

        getIsLogin() {
            if (uni.getStorageSync('AUTHORIZATION')) {
                return true;
            } else {
                return false;
            }
        },

        // 监听页面滚动事件
        handletouchmove(event) {
            let currentY = event.changedTouches[0].clientY; // console.log(currentY);

            if (currentY <= this.startY) {
                this.setData({
                    // btmTop: currentY > 200 ? currentY : 200,
                    btmTop: 200,
                    isScroll: true
                }); // console.log("上滑");
            } else {
                this.setData({
                    showSearch: false,
                    btmTop: 890,
                    isScroll: false,
                    showBack: false
                }); // console.log("下滑");
            }
        },

        //滑动开始事件
        handletouchstart: function (event) {
            this.setData({
                startY: event.changedTouches[0].clientY
            }); // this.data.startY = event.changedTouches[0].clientY;
            // console.log(this.data.startY);
        },

        //触摸结束
        handlerouchend(event) {
            let currentY = event.changedTouches[0].clientY; // console.log('初始是'+this.data.startY)
            // console.log('现在是'+currentY)

            if (currentY < this.startY) {
                this.setData({
                    btmTop: 200,
                    isScroll: true
                });
            }
        },

        //回到开始位置
        tapDown() {
            this.setData({
                showSearch: false,
                btmTop: 890,
                isScroll: false,
                showBack: false
            });
        },

        /**
         * 搜索框失去焦点-若搜索内容为空，则默认返回
         */
        inputBlur() {
            if (this.autoSearch == '') {
                this.clearInput();
                this.tapDown();
            }
        },

        /**
         * 搜索框聚焦
         */
        focusInput() {
            // let that = this;
            // this.setData({
            //   btmTop: this.data.btmTop==200?200:500,
            //   showSearch:true,
            //   isScroll: true,
            //   showBack:true,
            // });
            uni.navigateTo({
                url: '../searchParkspace/searchParkspace'
            });
        },

        /**
         * 搜索框点击返回
         */
        goBack() {
            this.clearInput();
            this.tapDown();
        },

        goBack2() {
            uni.navigateBack({
                delta: 1
            });
        },

        //清除搜索框输入内容
        clearInput() {
            this.setData({
                autoSearch: '',
                isSearch: 0,
                showSearch: false,
                isSearching: false,
                showBack: false,
                searchName: '',
                center: [this.longitude, this.latitude],
                addressList: []
            });
            uni.removeStorageSync('searchHistory');
            this.getCurLocation();
        },

        clearInput2() {
            this.setData({
                autoSearch: '',
                isSearch: 0,
                showSearch: false,
                isSearching: false,
                showBack: false,
                // searchName: "",
                center: [this.longitude, this.latitude],
                addressList: []
            });
            uni.removeStorageSync('searchHistory');
            this.getCurLocation();
        },

        //搜索框输入中事件
        getAddress(e) {
            this.setData({
                autoSearch: e.detail
            });

            if (e.detail.length > 0) {
                this.setData({
                    isSearching: true
                });
            } else {
                this.setData({
                    isSearching: false
                });
            }

            this.getPoi();
        },

        /**
         * 搜索地址的方法--必须在以下地址里为对应的小程序购买服务，并将订单数据下的appid放到下面的“service"中
         * https://fuwu.weixin.qq.com/service/detail/00002c301c0ac83ddc996d8ca56015
         */
        getPoi() {
            const data = {
                keyword: this.autoSearch,
                boundary: 'region(杭州)'
            };
            uni.serviceMarket
                .invokeService({
                    service: 'wxc1c68623b7bdea7b',
                    api: 'poiSearch',
                    data: data
                })
                .then((res) => {
                    const result = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
                    this.setData({
                        addressList: result.data
                    });
                })
                .catch((err) => {
                    console.error(err);
                });
        },

        /**选择搜索的列表里的地址 */
        selectAddr(e) {
            if (this.markers[this.markers.length - 1].id == 'poiMarker') {
                this.markers.splice(this.markers.length - 1, 1);
            } // let data = e.currentTarget.dataset.data

            let data = e;
            let lng = data.location ? data.location.split(',')[0] : '';
            let lat = data.location ? data.location.split(',')[1] : '';
            this.setData({
                // autoSearch:data.title,
                // longitude: data.location.lng,
                // latitude: data.location.lat,
                longitude: lng,
                latitude: lat,
                isSearch: 1,
                // showSearch:false,
                center: [lng, lat],
                markers: this.markers.concat({
                    latitude: lat,
                    longitude: lng,
                    iconPath: '/static/pages/index2/imgs/marker.png',
                    width: 25,
                    height: 41,
                    id: 'poiMarker'
                })
            });
            uni.showLoading({
                title: '加载中'
            });
            this.setData({
                isShowLoading: true
            });
            this.getParklist();
            this.tapDown();
            uni.removeStorageSync('isSearching'); //查询完就移除掉
        },

        /**
         * 搜索列表的导航
         */
        gotoNavigate(e) {
            // console.log(e);
            const data = e.currentTarget.dataset.data;
            let param = {
                latitude: Number(data.location.lat),
                longitude: Number(data.location.lng),
                address: data.address
            };
            this.onRunApi(param);
        },

        /**调用导航 */

        /**需要引入util判断版本
     * @param {e} e 参数e是一个对象
     * address:目标地址，必填
     * latitude:目标地址纬度,必须是number类型
     * longitude：目标地址经度，必须是number类型
     * 必须在wxml页面创建一个地图，若是不展示地图则将地图设置hidden=true,可将下列代码直接复制
     * <view hidden="true">
      <map
          class="map"
          id="mymap"
      >
        </map>
      </view>
     */
        onRunApi(e) {
            const version = uni.getSystemInfoSync().SDKVersion;

            if (util.compareVersion(version, '2.14.0') < 0) {
                uni.showToast({
                    title: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。',
                    icon: 'none'
                });
                return;
            }
			if(uni.getStorageSync('weixin') == 2){
				jWeixin.miniProgram.navigateTo({
					url: "/pages/map/map?lat=" + e.latitude + '&long=' + e.longitude
				})
			}else{
				// window.location.href = 'http://api.map.baidu.com/marker?location=' + e.latitude + ',' + e.longitude +'&title='+ e.address +'&content=&output=html' //百度
				// window.location.href = 'http://apis.map.qq.com/uri/v1/marker?marker=coord:' + e.latitude + ',' + e.longitude +';addr:'+ e.address   //腾讯导航
				window.location.href = 'http://uri.amap.com/marker?position=' + e.latitude + ',' + e.longitude +'&name='+ e.address +'&coordinate=gaode&callnative=1'  //高德
			}
			// window.location.href = 'http://api.map.baidu.com/marker?location=' + e.latitude + ',' + e.longitude +'&title='+ e.address +'&content=&output=html' //百度
			// window.location.href = 'http://apis.map.qq.com/uri/v1/marker?marker=coord:' + e.latitude + ',' + e.longitude +';addr:'+ e.address   //腾讯导航
			// window.location.href = 'http://uri.amap.com/marker?position=' + e.latitude + ',' + e.longitude +'&name='+ e.address +'&coordinate=gaode&callnative=1'  //高德
            // const mapCtx = uni.createMapContext('mymap');
            // mapCtx.openMapApp({
            //     latitude: e.latitude,
            //     longitude: e.longitude,
            //     destination: e.address,
            //     complete: (res) => {
            //         // console.log(res);
            //     }
            // });
        },

        imageLoad: function () {
            var that = this;
            uni.getSystemInfo({
                success: function (res) {
                    //我们设计图片的尺寸是750*388
                    var width = res.windowWidth; //获取当前屏幕的宽度

                    var rao = 750 / width; //图片宽度／屏幕的宽度

                    var height = 288 / rao; //图片高度／比例

                    that.setData({
                        imgheights: height //设置等比缩放的宽度
                    });
                }
            });
        },

        openSetting() {
            uni.openSetting();
        },

        /**
         * 页面埋点
         */
        setLog(e) {
            let param = {
                operation: e
            };
            util.request(api.setLog, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    if (res.success) {
                        // console.log('log')
                    }
                })
                .catch((err) => {
                    // console.log(err)
                });
        },

        /*是否有未支付订单 */
        isWaitingtopay() {
            let param = {
                unionId: uni.getStorageSync('unionId')
            };
            util.request(api.isWaitingtopay, param, 'POST', 'application/x-www-form-urlencoded')
                .then((res) => {
                    if (res.success) {
                        this.setData({
                            isShowPayTip: res.data == -1 ? false : true,
                            gotopayType: res.data
                        });
                    }
                })
                .catch((err) => {
                    // console.log(err)
                });
        },

        /**跳转支付 */
        gotoPay(e, _dataset) {
            /* ---处理dataset begin--- */
            // this.datasetHandle(e, _dataset);
            /* ---处理dataset end--- */
            uni.navigateTo({
                url: '../order/index?type=' + this.gotopayType
            });
        },

        /**
         * 打开下拉框选择
         */
        showDropDown() {
            this.$mp.page.selectComponent('#dropdown').toggle();
            this.setData({
                showDropdown: true
            });
        },

        //关闭下拉选择
        closedrop() {
            this.setData({
                showDropdown: false
            });
        },

        noResponse() {
            // console.log('你点了')
        },

        // 使用高德提供的天气
        getWeather() {
            let that = this;
            var myAmapFun = new amapFile.AMapWX({
                key: 'a29210026b1d7fd7df6f765b2588c301'
            });
            myAmapFun.getWeather({
                success: function (data) {
                    // console.log(data)
                    that.setData({
                        weather: data.liveData
                    }); //成功回调
                },
                fail: function (info) {
                    //失败回调
                    // console.log(info)
                }
            });
        },

        // 获取限牌
        getTrafficControl() {
            util.request(api.getTrafficControl, '', 'GET')
                .then((res) => {
                    if (res.success) {
                        this.setData({
                            controlNo: res.data == null ? '' : res.data.join(' ')
                        });
                    }
                })
                .catch((err) => {
                    // console.log(err)
                });
        },

        /**  点击跳转添加车牌 */
        gotoAddLicense(e, _dataset) {
            /* ---处理dataset begin--- */
            // this.datasetHandle(e, _dataset);
            /* ---处理dataset end--- */
            uni.navigateTo({
                url: '../addLicense/addLicense'
            });
        },

        // 加入我们
        gotoJoin() {
            uni.navigateTo({
                url: '../joinUS/joinUS'
            });
        },

        /**
         * 用户点击右上角分享
         */
        // onShareAppMessage: function () {
        // },
        // 地铁区域列表下拉框是否隐藏
        listqy: function (e) {
            if (this.qyopen) {
                this.setData({
                    qyopen: false,
                    shownavindex: 0
                });
            } else {
                this.setData({
                    qyopen: true,
                    qyshow: false,
                    isfull: true,
                    shownavindex: e.currentTarget.dataset.nav
                });
            }
        },

        // 地铁区域第一栏选择内容
        selectleft: function (e) {
            console.log('用户选中左边菜单栏的索引值是：' + e.target.dataset.city);
            this.setData({
                cityright: {},
                citycenter: this.cityleft[e.currentTarget.dataset.city],
                select1: e.target.dataset.city,
                select2: ''
            });
        },

        // 地铁区域中间栏选择的内容
        selectcenter1: function (e) {
            this.setData({
                cityright: this.citycenter[e.currentTarget.dataset.city],
                select2: e.currentTarget.dataset.city
            });
        },

        // 地铁区域中间栏选择的内容
        selectcenter2: function (e) {
            this.setData({
                cityright: this.citycenter[e.currentTarget.dataset.city],
                select3: e.currentTarget.dataset.city
            });
        },

        // 地铁区域中间栏选择的内容
        selectcenter3: function (e) {
            this.setData({
                cityright: this.citycenter[e.currentTarget.dataset.city],
                select4: e.currentTarget.dataset.city
            });
        },

        // 地铁区域左边栏选择的内容
        selectright: function (e) {
            console.log('选中地铁线下的地铁站' + e.currentTarget.dataset.city);
            this.setData({
                select5: e.currentTarget.dataset.city
            });
        },

        // 点击灰色背景隐藏所有的筛选内容
        hidebg: function (e) {
            this.setData({
                qyopen: false,
                // qyshow: true,
                isfull: false,
                shownavindex: 0
            });
        },

        // 地铁区域清空筛选项
        quyuEmpty: function () {
            this.setData({
                select1: '',
                select2: '',
                select3: '-1'
            });
        },

        // 地铁区域选择筛选项后，点击提交
        submitFilter: function () {
            // 隐藏地铁区域下拉框
            this.setData({
                qyopen: false,
                qyshow: false,
                isfull: false,
                shownavindex: 0
            });
            this.setData({
                allParkFlag: true
            });
            uni.showLoading({
                title: '加载中...'
            });
            this.setData({
                isShowLoading: true
            });
            this.getParklist();
        },
		goMap(){
			uni.navigateTo({
				url:'../index/index'
			})
		}
    }
};
</script>
<style>
@import './index.css';
</style>
